package org.xhy.hrm.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.xhy.hrm.doc.CourseDoc;
import org.xhy.hrm.doc.query.CourseESQuery;
import org.xhy.hrm.service.ICourseESService;
import org.xhy.hrm.util.AjaxResult;
import org.xhy.hrm.util.PageList;

@RestController
@RequestMapping("/es/course")
public class CourseESController {

    @Autowired
    private ICourseESService courseESService;

    @PostMapping("/search")
    public AjaxResult search(@RequestBody CourseESQuery query){
        PageList pageList = courseESService.search(query);
        return AjaxResult.me().setResultObj(pageList);
    }

    @PostMapping("/save")
    @PreAuthorize("hasAuthority('es:saveCourse')")
    public AjaxResult save(@RequestBody CourseDoc courseDoc){
        courseESService.save(courseDoc);
        return AjaxResult.me();
    }

    @DeleteMapping("/del/{id}")
    public AjaxResult deleteById(@PathVariable("id") Long id){
        courseESService.deleteById(id);
        return AjaxResult.me();
    }
}
